package ast.stmt;

import icg.Quadruple;
import ts.SymbolTable;
import ast.Node;
import ast.exp.Expression;
import ast.type.Type;

public class ReadStmt extends Statement {
	private Expression exp;

	public ReadStmt(Expression exp) {
		this.exp = exp;
	}

	@Override
	public String toString() {
		return "<ReadStmt>\n" + exp + "\n</ReadStmt>";
	}

	@Override
	public void typeCheck(Type type) {
		Type typeExp = exp.typeCheck();
		if (typeExp != Type.INTEGER) {
			System.out.println("invalid expression on Read statement");
			SymbolTable.errors++;
		}
	}

	@Override
	public void genCode() {
		exp.genCode();
		Node.icg.gen(Quadruple.read(exp.addr));
	}
}
